#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
//https://www.luogu.com.cn/problem/P2660
using namespace std;
typedef long long LL;
LL x, y;
int main()
{
	cin >> x >> y;
	LL res = 0;
	LL a = x, b = y;//ʹa < b
	while (a > 0 && b > 0)
	{
		if (a > b)
		{
			swap(a, b);
		}
		res += b / a*a;
		b = b % a;
	}
	res *= 4;
	cout << res << endl;


	return 0;
}